# the minimum version of CMake
project(rnoh_pager_view)
cmake_minimum_required(VERSION 3.13)
set(CMAKE_VERBOSE_MAKEFILE on)

set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_SKIP_BUILD_RPATH TRUE)
# 设置模块路径
set(RNOH_GENERATED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/generated")
set(OH_MODULE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../oh_modules")
set(NATIVERENDER_ROOT_PATH "${CMAKE_CURRENT_SOURCE_DIR}")
set(RNOH_CPP_DIR "${OH_MODULE_DIR}/@rnoh/react-native-openharmony/include")
set(REACT_COMMON_PATCH_DIR "${RNOH_CPP_DIR}/patches/react_native_core")
# 设置日志等级
set(LOG_VERBOSITY_LEVEL 1)
# 汇编器和 C++ 编译器选项
set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -Wno-error=unused-command-line-argument -Qunused-arguments")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstack-protector-strong -Wl,-z,relro,-z,now,-z,noexecstack -s -fPIE -DIe -DNDEBUG")
# 宏定义
add_compile_definitions(WITH_HITRACE_SYSTRACE)
# folly 相关编译选项
set(folly_compile_options
    -DFOLLY_NO_CONFIG=1
    -DFOLLY_MOBILE=1
    -DFOLLY_USE_LIBCPP=1
    -DFOLLY_HAVE_RECVMMSG=1
    -DFOLLY_HAVE_PTHREAD=1
    -Wno-comma
    -Wno-shorten-64-to-32
    -Wno-documentation
    -faligned-new
)
add_compile_options("-Wno-unused-command-line-argument")

include_directories(
  ${NATIVERENDER_ROOT_PATH}
  ${RNOH_CPP_DIR}
  ${REACT_COMMON_PATCH_DIR}
  ${RNOH_CPP_DIR}/third-party/folly
  ${RNOH_CPP_DIR}/third-party/rn/ReactCommon
  ${RNOH_CPP_DIR}/third-party/rn/ReactCommon/react/nativemodule/core
  ${RNOH_CPP_DIR}/third-party/rn/ReactCommon/jsi
  ${RNOH_CPP_DIR}/third-party/rn/ReactCommon/callinvoker
  ${RNOH_CPP_DIR}/third-party/boost/libs/utility/include
  ${RNOH_CPP_DIR}/third-party/boost/libs/stacktrace/include
  ${RNOH_CPP_DIR}/third-party/boost/libs/predef/include
  ${RNOH_CPP_DIR}/third-party/boost/libs/array/include
  ${RNOH_CPP_DIR}/third-party/boost/libs/throw_exception/include
  ${RNOH_CPP_DIR}/third-party/boost/libs/config/include
  ${RNOH_CPP_DIR}/third-party/boost/libs/core/include
  ${RNOH_CPP_DIR}/third-party/boost/libs/preprocessor/include
  ${RNOH_CPP_DIR}/third-party/double-conversion
  ${RNOH_CPP_DIR}/third-party/rn/ReactCommon/react/renderer/graphics/platform/cxx
  ${RNOH_CPP_DIR}/third-party/rn/ReactCommon/runtimeexecutor
  ${RNOH_CPP_DIR}/third-party/glog/src
  ${RNOH_CPP_DIR}/third-party/boost/libs/mpl/include
  ${RNOH_CPP_DIR}/third-party/boost/libs/type_traits/include
  ${RNOH_CPP_DIR}/third-party/rn/ReactCommon/yoga
  ${RNOH_CPP_DIR}/third-party/boost/libs/intrusive/include
  ${RNOH_CPP_DIR}/third-party/boost/libs/assert/include
  ${RNOH_CPP_DIR}/third-party/boost/libs/move/include
  ${RNOH_CPP_DIR}/third-party/boost/libs/static_assert/include
  ${RNOH_CPP_DIR}/third-party/boost/libs/container_hash/include
  ${RNOH_CPP_DIR}/third-party/boost/libs/describe/include
  ${RNOH_CPP_DIR}/third-party/boost/libs/mp11/include
  ${RNOH_CPP_DIR}/third-party/boost/libs/iterator/include
  ${RNOH_CPP_DIR}/third-party/boost/libs/detail/include
  ${RNOH_CPP_DIR}/patches/react_native_core/react/renderer/textlayoutmanager/platform/harmony
  ${RNOH_CPP_DIR}/third-party/hermes/public
  ${RNOH_CPP_DIR}/third-party/hermes/API
)

# 配置 folly 的头文件
configure_file(
  ${RNOH_CPP_DIR}/third-party/folly/CMake/folly-config.h.cmake
  ${RNOH_CPP_DIR}/third-party/folly/folly/folly-config.h
)

file(GLOB_RECURSE rnoh_pager_view_SRC
    "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp"
    "${RNOH_GENERATED_DIR}/**/*.cpp"
)
add_library(rnoh_pager_view SHARED ${rnoh_pager_view_SRC}
    "${RNOH_CPP_DIR}/RNOHOther.cpp"
    "${RNOH_CPP_DIR}/third-party/folly/folly/lang/SafeAssert.cpp"
)

# 导入 rnoh 所需的原生库目录
target_link_directories(rnoh_pager_view PUBLIC
  ${OH_MODULE_DIR}/@rnoh/react-native-openharmony/libs/arm64-v8a
)

# 链接所需的原生和 React Native 模块库
target_link_libraries(rnoh_pager_view PUBLIC
  rnoh_semi
  libc++_shared.so
  libace_napi.z.so
  libace_ndk.z.so
  librawfile.z.so
  libhilog_ndk.z.so
  libnative_vsync.so
  libnative_drawing.so
  libhitrace_ndk.z.so
  # React Native 模块
  hermes
  jsi
  jsinspector
  logger
  runtimeexecutor
  # React Core 系列库
  react_config
  react_debug
  react_utils
  # NativeModule 核心
  react_nativemodule_core
  # Render 系列
  react_render_scheduler
  react_render_core
  react_render_debug
  react_render_graphics
  react_render_telemetry
  react_render_animations
  react_render_mounting
  react_render_textlayoutmanager
  react_render_templateprocessor
  react_render_componentregistry
  react_render_attributedstring
  react_render_imagemanager
  react_render_leakchecker
  react_render_runtimescheduler
  react_render_mapbuffer
  # RRC（Render React Component）
  rrc_root
  rrc_view
  rrc_text
  rrc_textinput
  rrc_image
  rrc_scrollview
)

target_include_directories(rnoh_pager_view PUBLIC
    ${CMAKE_CURRENT_SOURCE_DIR}
    ${RNOH_GENERATED_DIR}
    )
#target_link_libraries(rnoh_pager_view PUBLIC rnoh)

target_compile_options(rnoh_pager_view PUBLIC
  ${folly_compile_options}
  -DRAW_PROPS_ENABLED
  -std=c++17
)
